home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / arpdump.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  1KB  |  61 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "arp.h"
  6. #include "ax25.h"
  7.  
  8. extern FILE *trfp;
  9.  
  10. arp_dump(bpp)
  11. struct mbuf **bpp;
  12. {
  13.     struct arp arp;
  14.     char *inet_ntoa();
  15.     struct arp_type *at;
  16.     int is_ip = 0;
  17.  
  18.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  19.         return;
  20.     fprintf(trfp,"ARP: len %d",len_mbuf(*bpp));
  21.     if(ntoharp(&arp,bpp) == -1){
  22.         fprintf(trfp," bad packet\n");
  23.         return;
  24.     }
  25.     /* Print hardware type in Ascii if known, numerically if not */
  26.     if(arp.hardware < NHWTYPES){
  27.         at = &arp_type[arp.hardware];
  28.         fprintf(trfp," hwtype %s",arptypes[arp.hardware]);
  29.     } else {
  30.         at = NULLATYPE;
  31.         fprintf(trfp," hwtype %u",arp.hardware);
  32.     }
  33.     /* Print hardware length only if unknown type, or if it doesn't match
  34.      * the length in the known types table
  35.      */
  36.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  37.         fprintf(trfp," hwlen %u",arp.hwalen);
  38.  
  39.     /* Check for most common case -- upper level protocol is IP */
  40.     if(at != NULLATYPE && arp.protocol == at->iptype){
  41.         fprintf(trfp," prot IP");
  42.         is_ip = 1;
  43.     } else {
  44.         fprintf(trfp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  45.     }
  46.     switch(arp.opcode){
  47.     case ARP_REQUEST:
  48.         fprintf(trfp," op REQUEST");
  49.         break;
  50.     case ARP_REPLY:
  51.         fprintf(trfp," op REPLY");
  52.         break;
  53.     default:
  54.         fprintf(trfp," op %u",arp.opcode);
  55.         break;
  56.     }
  57.     if(is_ip)
  58.         fprintf(trfp," target %s",inet_ntoa(arp.tprotaddr));
  59.     fprintf(trfp,"\n");
  60. }
  61.